﻿using BLL;
using Model;
using System.Data;

namespace StudentClubMisWf
{
    public partial class frmUserLogin : Form
    {
        public frmUserLogin()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 用户登录验证
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string userName = txtUserName.Text;
            string password = txtPassword.Text;
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
            {
                lblInfomation.Text = "请输入用户名和密码";
            }
            else
            {
                try
                {
                    ClubUserBLL clubUserBLL = new ClubUserBLL();
                    List<ClubUser> users = clubUserBLL.GetAllUserList();
                    if (users.Where(u => u.UserName == userName && u.Password == password).Any())
                    {
                        lblInfomation.Text = "登录成功！";
                        MessageBox.Show("登录成功！");
                        this.Hide();
                        frmClubUser frmClubUser = new frmClubUser();
                        frmClubUser.ShowDialog();
                    }
                    else
                    {
                        lblInfomation.Text = "用户名或密码错误！";
                    }
                }
                catch (Exception)
                {

                    lblInfomation.Text = "数据库连接错误，请检查数据库！";
                }

            }
        }

        private void frmUserLogin_Load(object sender, EventArgs e)
        {

        }
    }
}
